/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2025-02-19 09:38:23
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-19 10:29:35
 * @FilePath: /vue3-admin-server/src/common/dto/page.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { Type } from 'class-transformer';
import {
    IsNotEmpty,
    IsInt,
    IsString,
    IsEnum,
    IsArray,
    ValidateNested
} from 'class-validator';
import { BaseEntity } from 'src/entities/base.entity';

export class SortItemDTO<T> {
    @IsString()
    column: keyof T;

    @IsEnum(['asc', 'desc'])
    order: 'asc' | 'desc';
}

export class PageDTO<T extends BaseEntity> {
    @IsNotEmpty({ message: '页码不能为空' })
    @IsInt({ message: '页码必须是整型数字' })
    current: number;

    @IsInt({ message: '页大小必须是整型数字' })
    size = 10;

    @IsArray()
    @ValidateNested({ each: true })
    @Type(() => SortItemDTO<T>)
    sortList: SortItemDTO<T>[];
}
